﻿namespace WcfComposition.Tests
{
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using System;
    using System.Linq;

    /// <summary>
    /// Unit tests for the <see cref="ComposingServiceHost"/> class.
    /// </summary>
    [TestClass]
    public class ComposingServiceHostTests
    {
        #region Methods

        [TestMethod]
        public void ServiceHostShouldLoadComposingBehavior()
        {
            var addresses = new Uri[1];
            addresses[0] = new Uri( "http://localhost" );

            var target = new ComposingServiceHost( typeof( FakeService ), addresses );

            var behavior = ( from b in target.Description.Behaviors
                             where b.GetType() == typeof( ComposingServiceBehavior )
                             select b );

            Assert.IsTrue( behavior.Count() == 1 );
        }

        [TestMethod]
        public void ServiceHostShouldThrowNullExceptionWithNullType()
        {
            var addresses = new Uri[1];
            addresses[0] = new Uri( "http://localhost" );
            var errored = false;

            try
            {
                var target = new ComposingServiceHost( null, addresses );
            }
            catch ( ArgumentNullException nullException )
            {
                errored = true;
            }

            Assert.IsTrue( errored );
        }

        [TestMethod]
        public void ServiceHostShouldThrowNullExceptionWithNullAddresses()
        {
            var errored = false;

            try
            {
                var target = new ComposingServiceHost( typeof( FakeService ), null );
            }
            catch ( ArgumentNullException nullException )
            {
                errored = true;
            }

            Assert.IsTrue( errored );
        }

        #endregion
    }
}
